#include "debug.h"
#include "tos_k.h"
#include "dht.h"

#define DHT22_TASK_STK_SIZE       1024
k_task_t dht22_task;
__aligned(8) uint8_t dht22_task_stk[DHT22_TASK_STK_SIZE];

#define MQTT_TASK_STK_SIZE          2048
k_task_t mqtt_task;
__aligned(8) uint8_t mqtt_task_stk[MQTT_TASK_STK_SIZE];

#define SGP30_TASK_STK_SIZE       4096
k_task_t sgp30_task;
__aligned(8) uint8_t sgp30_task_stk[SGP30_TASK_STK_SIZE];

#define SHT40_TASK_STK_SIZE       4096
k_task_t sht40_task;
__aligned(8) uint8_t sht40_task_stk[SHT40_TASK_STK_SIZE];

extern void mqtt_entry(void *arg);
extern void dht22_entry(void *arg);
extern void sgp30_entry(void *arg);
extern void sht40_entry(void *arg);

extern int sht40_test();

k_msg_q_t msg_q;
uint8_t DataMsgPool[100];
k_mutex_t mutex;
int main(void)
{
    Delay_Init();
    USART_Printf_Init(115200);
    printf("SystemClk:%d\r\n",SystemCoreClock);

    printf("Welcome to TencentOS tiny(%s)\r\n", TOS_VERSION);

    tos_knl_init();
    tos_msg_q_create(&msg_q, DataMsgPool, 100);
    tos_mutex_create(&mutex);
    tos_task_create(&mqtt_task, "mqtt_task", mqtt_entry, NULL, 4, mqtt_task_stk, MQTT_TASK_STK_SIZE, 0);
    //tos_task_create(&dht22_task, "dht22_task", dht22_entry, NULL, 4, dht22_task_stk, DHT22_TASK_STK_SIZE, 0);
    tos_task_create(&sgp30_task, "sgp30_task", sgp30_entry, NULL, 5, sgp30_task_stk, SGP30_TASK_STK_SIZE, 0);
    tos_task_create(&sht40_task, "sht40_task", sht40_entry, NULL, 6, sht40_task_stk, SHT40_TASK_STK_SIZE, 0);
    tos_knl_start();

    printf("should not run at here!\r\n");
    while(1);
}
